package com.hdit.rpc.ServiceClasses
{
	import com.hdit.rpc.AsyncResponder;
	import com.hdit.rpc.IInvokeResponder;
	import com.hdit.rpc.IInvoker;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.http.HTTPMultiService;
	import mx.rpc.http.Operation;

	public class HTTPServiceInvoker extends EventDispatcher implements IInvoker
	{
		private var http:HTTPMultiService;
		private var _defaultHandler:Function;
		public function HTTPServiceInvoker(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		public function invoker(dest:String, method:String, args:Array, defaultHandler:Function,resultFormat:String="object"):IInvokeResponder
		{
			http=new HTTPMultiService();
			http.resultFormat=resultFormat;
			http.method="POST";
			this._defaultHandler=defaultHandler;
			var oper:Operation=new Operation(http,method);
			oper.url=dest;
			oper.method=method;
			var token:AsyncToken=oper.send.apply(null,args);
			return new AsyncResponder(token,_defaultHandler);
		}
	}
}